<?php
namespace  App\Http\Controllers\Radius;
use  App\Http\Controllers\Controller;

use App\Order;
use App\Rad_user;
use App\Rad_user_account;
use App\Usernew;
use Illuminate\Http\Request;

use App\Common\ErrorDefine;

use App\Radacct;
use App\Radcheck;
use App\Radgroupcheck;
use App\Radreply;
use App\Radusergroup;
use App\Rad_manage;
use App\Radgroupreply;
use App\Rad_users;
use App\Rad_account;

use DB;

use App\Line;
use App\Agent;


class  CrontabController extends Controller
{


    public function deleteExpiredAccount()
    {
        $time = date('Y-m-d H:i:s',time()-86400);


        $username =  Rad_users::where('qq',' ')->where('mobile',' ')->where('expired_at','<',$time)->get(['username']);


        if(!empty($username))
        {
           foreach($username as $name)
           {
               $Radcheck  = Radcheck::where('username',$name->username)->delete();
               if($Radcheck)
               {
                   echo "Radcheck 删除 $name->username 成功<br>";
               }else{
                   echo "Radcheck 删除 $name->username 失败<br>";
               }

               $group = Radusergroup::where('username',$name->username)->delete();

               if($group)
               {
                   echo "Radusergroup 删除 $name->username成功<br>";
               }else{
                   echo "Radusergroup 删除 $name->username 失败<br>";
               }


              $radreply =  Radreply::where('username',$name->username)->delete();

               if($radreply)
               {
                   echo "Radreply 删除-- $name->username--- 成功<br>";
               }else{
                   echo "Radreply 删除 --  $name->username--失败<br>";
               }
               $users=  Rad_users::where('username',$name->username)->delete();

               if($users)
               {
                   echo "Rad_users 删除-- $name->username--- 成功<br>";
               }else{
                   echo "Rad_users 删除 --  $name->username--失败<br>";
               }

           }
        }

    }

    // 线路列表
    public function updateLinelist()
    {
        $where['enable_flag'] = 1;

        $lines = Line::where($where)->get();


        foreach($lines as $line)
        {
            $str = strstr($line->niumoip, '.', TRUE);
            $line->niumoip = $str.'.niumoip.com';
            $line->save();
        }

    }

}















